package yadong.demo.wifichecker;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.WifiManager;

public class BoradcastMy extends BroadcastReceiver {

	@Override
	public void onReceive(Context context, Intent intent) {
		String action = intent.getAction();
		int extra = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE,
				WifiManager.WIFI_STATE_UNKNOWN);
		NetworkInfo info = intent
				.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
		Logger.v(this,"action = " + action + " extra = " + extra
				+ " info=" + (info == null ? "null" : info.getType())
				+ " state = " + (info == null ? "null" : info.getState()));
		if (info != null
				&& ConnectivityManager.CONNECTIVITY_ACTION.equals(action)
				&& ConnectivityManager.TYPE_WIFI == info.getType()
				&& NetworkInfo.State.CONNECTED == info.getState()) {
			Intent intent2 = new Intent();
			intent2.setClassName("yadong.demo.wifichecker",
					"yadong.demo.wifichecker.ServiceMain");
			context.startService(intent2);
		}
	}

}
